#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
const int MAXN=1e6+10;
LL n,a,b,c,f[MAXN],sum[MAXN],q[MAXN];
db slope(LL x,LL y)
{
	return (f[x]+a*sum[x]*sum[x]-b*sum[x]-(f[y]+a*sum[y]*sum[y]-b*sum[y]))*1.0/((sum[x]-sum[y])*a*2.0);
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	for(LL i=1;i<=n;++i)
	{
		scanf("%lld",&sum[i]);
		sum[i]+=sum[i-1];
	}
	LL l=0,r=0;
	for(LL i=1;i<=n;++i)
	{
		while(l<r&&slope(q[l],q[l+1])<sum[i])++l;
		LL t=q[l];
		f[i]=f[t]+a*(sum[i]-sum[t])*(sum[i]-sum[t])+b*(sum[i]-sum[t])+c;
		while(l<r&&slope(q[r-1],q[r])>=slope(q[r],i))--r;
		q[++r]=i;
	}
	printf("%lld\n",f[n]);
	return 0;
}
